//
//  FLSShopCell.m
//  ToListenPhone
//
//  Created by zhibao on 2023/7/21.
//

#import "FLSShopCell.h"
@interface FLSShopCell(){
    UIImageView *imgView;
    UILabel *titleLabel;
    UILabel *jifenLabel;
}
@end

@implementation FLSShopCell
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = MyColor(@"#F6F6F6");
        
        UIView *bgView = [UIView new];
        bgView.backgroundColor = UIColor.whiteColor;
        bgView.layer.cornerRadius = 10;
        [self addSubview:bgView];
        [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(5);
            make.right.bottom.mas_equalTo(-5);
        }];
        self.layer.cornerRadius = 10;
        imgView = [[UIImageView alloc] init];
        imgView.image = [UIImage imageNamed:@"fulishe_duihuan_shop_shangpin"];
        imgView.contentMode = UIViewContentModeScaleAspectFill;
        [bgView addSubview:imgView];
        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(32);
            make.centerX.equalTo(bgView);
        }];
        self.clipsToBounds = YES;
        
        titleLabel = [[UILabel alloc] init];
        titleLabel.font = MY_SCALE_RegularFONT(14);
        titleLabel.text = @"1天-VIP会员";
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
        [bgView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imgView.mas_bottom).offset(20);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];
        
        jifenLabel = [[UILabel alloc] init];
        jifenLabel.font = MY_SCALE_RegularFONT(14);
        jifenLabel.text = @"350积分";
        jifenLabel.textAlignment = NSTextAlignmentCenter;
        jifenLabel.textColor = [UIColor colorWithHexString:@"#F5605C"];
        [bgView addSubview:jifenLabel];
        [jifenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(3);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];
        
        UIButton *duihuanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [duihuanBtn setTitle:@"立即兑换" forState:UIControlStateNormal];
        [duihuanBtn addTarget:self action:@selector(duiuan) forControlEvents:UIControlEventTouchUpInside];
        duihuanBtn.backgroundColor = MyColor(@"#FFF6E8");
        [bgView addSubview:duihuanBtn];
        duihuanBtn.titleLabel.font = MY_SCALE_SemiboldFONT(15);
        [duihuanBtn setTitleColor:MyColor(@"#F19000") forState:UIControlStateNormal];
        duihuanBtn.layer.cornerRadius = 15;
        [duihuanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
            make.height.mas_equalTo(30);
            make.top.equalTo(jifenLabel.mas_bottom).offset(10);
        }];
    }
    return self;
}

- (void)update:(NSDictionary *)dic{
    NSString *product_id = dic[@"product_id"];
    NSArray *tempArray = [product_id componentsSeparatedByString:@"-"];
    titleLabel.text = [NSString stringWithFormat:@"%@天-VIP会员",tempArray.firstObject];
    jifenLabel.text = [NSString stringWithFormat:@"%@积分",dic[@"integral"]];
}

-(void)duiuan{
    if(self.duihuanBlock){
        self.duihuanBlock();
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

@end
